/**
 * 获取用户抽奖信息的mock数据
 */
export function getUserLuckyDrawInfo() {
  return {
    code: 0,
    message: 'success',
    data: {
      remainingChances: 3,
      totalEarned: 25,
      refreshCount: 3,
      refreshTime: '00:00:00'
    }
  }
}

/**
 * 获取奖品列表的mock数据
 */
export function getPrizeList() {
  return {
    code: 0,
    message: 'success',
    data: [
      { id: 1, name: "10 HDFS", color: "#FF6B6B", probability: "10%" },
      { id: 2, name: "5 HDFS", color: "#4ECDC4", probability: "15%" },
      { id: 3, name: "限量NFT", color: "#FFD166", probability: "5%" },
      { id: 4, name: "2 HDFS", color: "#6B5B95", probability: "15%" },
      { id: 5, name: "1 HDFS", color: "#FF8C42", probability: "15%" },
      { id: 6, name: "谢谢参与", color: "#88D8B0", probability: "40%" }
    ]
  }
}

/**
 * 执行抽奖的mock数据
 */
export function drawPrize() {
  // 使用加权随机算法，根据概率分配奖品
  const probabilities = [10, 15, 5, 15, 15, 40] // 对应prizes的概率
  const totalProbability = probabilities.reduce((sum, prob) => sum + prob, 0)
  const randomValue = Math.random() * totalProbability
  
  let cumulativeProbability = 0
  let randomPrizeIndex = 0
  
  for (let i = 0; i < probabilities.length; i++) {
    cumulativeProbability += probabilities[i]
    if (randomValue <= cumulativeProbability) {
      randomPrizeIndex = i
      break
    }
  }
  
  const prizes = [
    { id: 1, name: "10 HDFS", color: "#FF6B6B", probability: "10%" },
    { id: 2, name: "5 HDFS", color: "#4ECDC4", probability: "15%" },
    { id: 3, name: "限量NFT", color: "#FFD166", probability: "5%" },
    { id: 4, name: "2 HDFS", color: "#6B5B95", probability: "15%" },
    { id: 5, name: "1 HDFS", color: "#FF8C42", probability: "15%" },
    { id: 6, name: "谢谢参与", color: "#88D8B0", probability: "40%" }
  ]
  
  return {
    code: 0,
    message: 'success',
    data: {
      prizeIndex: randomPrizeIndex,
      prize: prizes[randomPrizeIndex],
      recordId: Date.now().toString(),
      remainingChances: Math.max(0, 3 - 1) // 模拟减少抽奖次数
    }
  }
}

/**
 * 领取奖品的mock数据
 */
export function claimPrize(data) {
  return {
    code: 0,
    message: 'success',
    data: {
      success: true,
      message: '奖品已发放到您的账户'
    }
  }
}

/**
 * 获取中奖记录的mock数据
 */
export function getPrizeRecords(params) {
  const { page = 1, pageSize = 10 } = params || {}
  
  const records = [
    {
      id: '1001',
      prizeId: 1,
      prizeName: '10 HDFS',
      prizeColor: '#FF6B6B',
      createTime: '2023-12-01 14:30:22',
      status: 'claimed', // claimed, unclaimed
      claimTime: '2023-12-01 14:35:10'
    },
    {
      id: '1002',
      prizeId: 3,
      prizeName: '限量NFT',
      prizeColor: '#FFD166',
      createTime: '2023-11-28 09:15:43',
      status: 'claimed',
      claimTime: '2023-11-28 09:16:20'
    },
    {
      id: '1003',
      prizeId: 2,
      prizeName: '5 HDFS',
      prizeColor: '#4ECDC4',
      createTime: '2023-11-25 18:22:05',
      status: 'claimed',
      claimTime: '2023-11-25 18:25:30'
    },
    {
      id: '1004',
      prizeId: 5,
      prizeName: '1 HDFS',
      prizeColor: '#FF8C42',
      createTime: '2023-11-20 11:05:18',
      status: 'claimed',
      claimTime: '2023-11-20 11:10:45'
    },
    {
      id: '1005',
      prizeId: 4,
      prizeName: '2 HDFS',
      prizeColor: '#6B5B95',
      createTime: '2023-11-15 16:40:33',
      status: 'claimed',
      claimTime: '2023-11-15 16:42:12'
    }
  ]
  
  const startIndex = (page - 1) * pageSize
  const endIndex = startIndex + pageSize
  const pageRecords = records.slice(startIndex, endIndex)
  
  return {
    code: 0,
    message: 'success',
    data: {
      list: pageRecords,
      total: records.length,
      page,
      pageSize
    }
  }
}